
import { store } from '../../store'
import { system as http, auth as authHttp } from '@zh/common-utils/http'

export { http }


/**
 * 通过岗位id查询角色信息
 * @param {*} jobBankId
 */
export function getRoleListByJobBankId (jobBankId) {
  return http.get('system/role/getRoleListByJobBankId?jobBankId=' + jobBankId)
}

/**
 * 用户分页
 * @param {Object} params
 */
export function userpage (params) {
  return http.post('system/SysUnituser/page', params)
}
/**
 * 用户分页 优化
 * @param {Oject} params
 * @returns
 */
export function userlistpage (params) {
  return http.post('system/SysUnituser/listPage', params)
}

/**
 * 用户分页new
 * @param {Object} params
 */
export function userpagenew (params) {
  return http.post('system/SysUnituser/page_new', params)
}

/**
 * 机构分页
 * @param {Object} params
 */
export function unitpage (params) {
  return http.post('system/SysUnitinfo/page', params)
}

/**
 *
 * @param {Long} topId
 */
export function syncUnitTree (topId) {
  return http.post('system/SysUnitinfo/syncUnitTree?topId=' + topId, null, {
    repeat: true
  })
}

/**
 * 查看密码
 * @param tempPassWord 密码
 * @param passwordSalt 盐
 */
export function showPassFun (tempPassWord, passwordSalt) {
  return http.get('system/SysUnituser/showPass/' + tempPassWord + '/' + passwordSalt)
}

/**
 * 解锁用户
 * @param {*} account
 */
export function resetUserLock (account) {
  return http.get('system/SysUnituser/resetUserLock?account=' + account)
}

/**
 * 新增用户，初始化
 * @param orgid 机构id
 */
export function init (orgid) {
  return http.get('system/SysUnituser/init/' + orgid)
}

/**
 * 修改用户，初始化
 * @param orgid 机构id
 */
export function getById (id) {
  return http.get('system/SysUnituser/getById/' + id)
}

/**
 * 用户角色下拉
 */
export function getRoleList () {
  return http.get('system/SysUnituser/getRoleList')
}

export function getAllRoleList () {
  return http.get('system/SysUnituser/getAllRoleList')
}

/**
 * 修改或保存用户
 * @param {Object} form 表单信息
 */
export function saveOrUpdate (form) {
  const url = form.id ? 'system/SysUnituser/update' : 'system/SysUnituser/save'
  return http.post(url, form)
}

/**
 * 修改或保存机构用户
 * @param {String} changeType 1：转岗；2：兼职
 * @param {Object} form 表单信息
 */
export function saveOrUpdateChange (changeType, form) {
  const url = changeType == '1' ? 'system/SysUnituser/changeUnituser' : 'system/SysUnituser/addUnituser'
  return http.post(url, form)
}

/**
 * 删除用户
 * @param {Long} id 机构id
 */
export function del (id) {
  return http.get('system/SysUnituser/delete/' + id)
}

/**
 * 转职初始化
 * @param {Long} unitid 机构id
 * @param {String} unittype 机构类型
 */
export function changeInit (unitid, unittype) {
  return http.get('system/SysUnituser/change/' + unitid + '/' + unittype)
}
/**
 * 获取登录用户信息
 * @returns
 */
export function getLoginUser (checkToken, handleError) {
  return authHttp.get(`/sys/sso/getUserSimleInfo?checkToken=${!!checkToken}`, {
    showLoading: false,
    handleError: handleError !== false
  })
}

/**
 * 获取接口分类
 * @param {} record
 * @returns
 */
export function recordBasic (record) {
  return http.get('system/SysDict/getCode/USER_STATUS', record)
}
/**
 * 获取用户详情
 * @param {*} record
 * @returns
 */
export function getUserInfo (id) {
  return http.get('system/SysUserinfo/getById/' + id)
}

export function changePassword (params) {
  return http.post('/system/SysUserinfo/updateUserPass', params)
}

export function sysApplicationUserList (params) {
  return http.post('app/sysApplicationUser/list', params)
}
export function userOrderTree (params) {
  return http.post('system/SysUnitinfo/userOrderTree', params)
}
export function userOrder (params) {
  return http.post('system/SysUnituser/userOrder', params)
}